#[derive(Debug)]
enum PersonId {
    // 括号里是和携带的数据的类型
    Passport(u32),
    UUID(String),
    IndentityCard(u32, u32, u32),
}

struct Person {
    name: String,
    last_name: String,
    age: u32,
    id: PersonId,
}

impl Person {
    // associated function
    // 这种方法适用于构造方法
    fn new() -> Person {
        Person {
            name: "default".to_string(),
            last_name: "default".to_string(),
            age: 0,
            id: PersonId::UUID("865fbd57-64b6-4064-8207-2368ead0436e".to_string()),
        }
    }

    fn from(name: String, last_name: String, age: u32, id: PersonId) -> Person {
        Person {
            name,
            last_name,
            age,
            id,
        }
    }

    fn display(&self) {
        println!(
            "{} {} {} {:?}",
            self.name, self.last_name, self.age, self.id
        );
    }

    fn change_age(&mut self, new_age: u32) {
        self.age = new_age;
    }
}

struct Animal(String);

fn main() {
    let mut p = Person::new();
    p.change_age(12);
    p.display();
    check_person_id(p.id);
}

fn check_person_id(id: PersonId) {
    if let PersonId::Passport(num) = id {
        println!("it match passport {}", num);
    } else {
        println!("it doesn't match");
    }

    match id {
        PersonId::IndentityCard(x, y, z) => {
            println!("id card first value: {}", x)
        }
        PersonId::Passport(x) => {
            println!("passport: {}", x)
        }
        PersonId::UUID(x) => {
            println!("uuid: {}", x)
        }
    }

    let animal = Animal("dog".to_string());
    let Animal(animal_type) = animal;

    println!("{}", animal_type);
}
